package com.lagou.pojo;

import com.lagou.session.Executor;
import com.lagou.session.SimpleExecutor;
import com.lagou.transaction.Transaction;

import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;

public class Configuration {

    private DataSource dataSource;

    protected String defaultExecutorType;

    /**
     * key: statementId  value:封装好的mappedStatement对象
     */
    Map<String,MappedStatement> mappedStatementMap = new HashMap<>();

    public DataSource getDataSource() {
        return dataSource;
    }

    public void setDataSource(DataSource dataSource) {
        this.dataSource = dataSource;
    }

    public Map<String, MappedStatement> getMappedStatementMap() {
        return mappedStatementMap;
    }

    public void setMappedStatementMap(Map<String, MappedStatement> mappedStatementMap) {
        this.mappedStatementMap = mappedStatementMap;
    }

    public Executor newExecutor(Transaction transaction, String executorType) {
        executorType = executorType == null ? this.defaultExecutorType : executorType;
        executorType = executorType == null ? "simple" : executorType;
        Executor executor;
        if ("simple" == executorType) {
            executor = new SimpleExecutor(transaction);
        }else {
            executor = null;
        }
        return executor;
    }
}
